$('.slide_1').hide();
// canvas
var canvas = document.getElementById('img_canvas');
var context = canvas.getContext('2d');

var flag = false;
context.beginPath();
var objImg = new Image();

objImg.src = 'img/a.png';

objImg.onload = function () {
    //var W=parseFloat(getStyle(canvas,'width'));
    //var H=parseFloat(getStyle(canvas,'height'));
    // var viewHeight = $(window).height();
    var W = window.innerWidth;
    var H = window.innerHeight;

    function getStyle(obj, attr) {
        return obj.currenStyle ? obj.currenStyle[attr] : window.getComputedStyle(obj, null)[attr];
    }
    //	console.log(W,H);
    context.drawImage(objImg, 0, 0, W, H);
    context.closePath();
    context.globalCompositeOperation = 'destination-out';

    context.lineWidth = 60;
    context.lineCap = 'round'; //线两端的形状
    context.lineJoin = 'round'; //线交叉处的形状
    canvas.addEventListener('touchstart', function (ev) {
        var e = ev.changedTouches[0];
        var x = e.clientX - canvas.offsetLeft;
        var y = e.clientY - canvas.offsetTop;
        //console.log(x,y);
        context.moveTo(x, y);
			if(!flag){
	        function move(ev) {
	            var e = ev.changedTouches[0];
	            var x2 = e.clientX - canvas.offsetLeft;
	            var y2 = e.clientY - canvas.offsetTop;
//	              console.log(x2, y2);	
	            context.lineTo(x2, y2);
	            context.stroke();
	            ev.preventDefault();
	        }
	
	        function end(ev) {
	            judge();
	            canvas.removeEventListener('touchmove', move, false);
	            canvas.removeEventListener('touchend', end, false);
	        }
	        canvas.addEventListener('touchmove', move, false);
	        canvas.addEventListener('touchend', end, false);
			}else{
				canvas.style.display='none';	
			}
				
    })
 function judge() {
        var data = context.getImageData(0, 0, W, H).data;
        var len = data.length;
        var cnt = 0;
        for (var i = 3; i < len; i += 4) {
            if (data[i] == 0) {
                cnt++;
            }
        }
        if (cnt / (len / 4) > 0.3) {
            context.clearRect(0, 0, W, H);
			flag=true;
			$('.slide_1').show();
			$('#music').addClass('active');			
			au.play();
        }
    }
}
var au = document.getElementsByTagName("audio")[0];
var music = document.getElementById('music');
musicFlag=false;
music.onclick=function(){
	if(!musicFlag){
		music.style.animationPlayState='paused';
		au.pause();
		musicFlag=true;
	}else{
		music.style.animationPlayState='running';
		au.play();
		musicFlag=false;
	}
	
}
var attr=['b.png','c.png','d.png','e.png','ad1.png','9.jpg','ad3.png','ad4.png','ad4.png','b.png'];
var swAll=document.querySelectorAll('.swiper-slide');
var len=swAll.length;
for(var i=0;i<len;i++){
	swAll[i].style.background='url(img/'+attr[i]+') no-repeat';
	swAll[i].style.backgroundSize='100% 100%';
}
//$('#music').on('tap',function(){
//	  animation-play-state: paused;
//	post();
//})
var attr2=['a.png','b.png','c.png','c1.png','c2.png','c4.png','c3.png',
'c4.png','c5.png','c6.png','logo.jpg','d1.png','music.png',
'arr.png',
'd.png','e.png','ad1.png','ad2.png','ad3.png','ad4.png'];
		var cnt=0;
		var len2=attr2.length;
		for(var i=0;i<len2;i++) {
			// 图片预加载
			var img = new Image();
			img.src = 'img/'+attr2[i];
			img.onload = function() {
				cnt++;
				if(cnt == len2) {
					//alert("全部加载完成。");
					$('#loading').hide();
					// 内容展示
				}
			}
		}

var swiper = new Swiper('.swiper-container', {
	//pagination: '.swiper-pagination',	
	paginationClickable: true,
	direction: 'vertical',
	loop:true,
	onSlideChangeEnd: function(swiper){
			console.log('事件触发了;');
	}
});

   
